import java.util.Stack;

public class Test {
    //有效的括号
    class Solution {
        public boolean isValid(String s) {
            Stack<String> strings = new Stack<>();
            for (int i = 0; i < s.length(); i++) {
                String tmp = String.valueOf(s.charAt(i));
                if(tmp.equals("(") || tmp.equals("{") ||tmp.equals("[")) {
                    strings.push(tmp);//左括号入栈
                }else {
                    if(strings.empty()) {//循环没走完，栈内空值(栈内用完，字符串剩余)
                        return false;
                    }
                    String tmp1 = strings.peek();
                    if(tmp.equals(")") && tmp1.equals("(") ||tmp.equals("}")
                            && tmp1.equals("{") ||tmp.equals("]") && tmp1.equals("[")) {
                        strings.pop();//左右括号匹配相消
                    }else {
                        return false;//(不匹配)
                    }
                }
            }
            return strings.empty();//循环走完，栈空符合，不空则返回false(栈内剩余，字符串用完)
        }
    }
    //逆波兰表达式求值
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < tokens.length; i++) {
            String tmp = tokens[i];
            if(tmp.equals("+") || tmp.equals("-") || tmp.equals("*") || tmp.equals("/")) {
                Integer a2 = stack.pop();
                Integer a1 = stack.pop();
                switch(tmp) {
                    case "+":
                        stack.push(a1+a2);
                        break;
                    case "-":
                        stack.push(a1-a2);
                        break;
                    case "*":
                        stack.push(a1*a2);
                        break;
                    case "/":
                        stack.push(a1/a2);
                        break;
                }
            }else {
                stack.push(Integer.parseInt(tmp));
            }
        }
        return stack.pop();
    }
    public static void main(String[] args) {
        String tmp = "ffwe";
        System.out.println(tmp.charAt(1));
    }
}
